<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>用户忘记密码</title>
    <meta name="_token" content="{{ csrf_token() }}"/>
    <link rel="stylesheet" href="/static/public/layui/css/layui.css">
    <link rel="stylesheet" href="/static/home/css/style.css">
    <script type="text/javascript" src="/static/public/layui/layui.js"></script>
</head>
<body>
<div class="layui-form">
    @csrf
    <div class="layui-form-item" style="margin-top: 20px">
        <label class="layui-form-label">手机号</label>
        <div class="layui-input-inline">
            <input type="number" name="phone" required  lay-verify="required" placeholder="请输入手机号" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">新密码</label>
        <div class="layui-input-inline">
            <input type="password" name="pwd" required lay-verify="required" placeholder="请输入密码" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">验证码</label>
        <div class="layui-input-inline"  style="width: 80px">
            <input type="text" class="layui-input" name="verifycode">
        </div>
        <button type="button" id="yzm" class="layui-btn" onclick="sendCode()">发送验证码</button>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" onclick="register();">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
    <div class="layui-form-item" style="margin-top: 40px">
        <div class="layui-input-block">
            <a href="javascript:;" style="margin-right: 15px" onclick="gout();"> 返回首页</a>
            <a href="javascript:;" onclick="goin()"> 返回登录页</a>
        </div>
    </div>

</div>

<script type="text/javascript">
    layui.use(['layer'],function () {
        $ = layui.jquery;
    });

    var countdown = 60;
    function settime(){
        if(countdown == 0){
            $('#yzm').attr('onclick','sendCode');
            $('#yzm').text('发送验证码');
            countdown = 60;
        }else{
            $('#yzm').attr("class","layui-btn layui-btn-disabled");
            $('#yzm').removeAttr('onclick','sendCode');
            $('#yzm').removeAttr('onclick','sendCode');
            $('#yzm').text('重新发送（'+countdown+'s)');
            countdown--;
            setTimeout(function () {
                settime();
            },1000);
        }
    }
    function sendCode() {

        var phone =  $.trim($('input[name="phone"]').val());
        var _token   = $('input[name="_token"]').val();
        if (!phone){
            return layer.alert('手机号不能为空',{icon:2});
        }

        // 3. 触发ajax，请求验证码,根据是否成功，给提示信息
        $.post('/sendcode',{phone:phone,_token:_token},function(data){
            if(data.code > 0){
                return layer.alert(data.msg,{icon:2});
            }
            layer.msg(data.msg);
            settime();
        },'json');

    }
    //返回首页
    function gout() {
        parent.window.location.href = '/';
    }
    function goin() {
        window.location.href = '/home/login';
    }





    //提交按钮
    function register() {
        var phone = $.trim($('input[name="phone"]').val());
        var pwd      = $.trim($('input[name="pwd"]').val());
        var verifycode = $.trim($('input[name="verifycode"]').val());
        var _token   = $('input[name="_token"]').val();
        if (phone==''){
            return layer.alert('请输入手机号',{icon:2});
        }
        if (pwd==''){
            return layer.alert('请输入密码',{icon:2});
        }
        if (verifycode==''){
            return layer.alert('请输入验证码',{icon:2});
        }
        $.post('/doforget',{_token:_token,phone:phone,pwd:pwd,verifycode:verifycode},function (res) {
            if (res.code>0){
                return layer.alert(res.msg,{icon:2});
            }
            layer.msg(res.msg);

            setTimeout(function () {
                window.location.href = '/home/login';
            },1000);

        },'json');
    }
    function keyLogin(){
        if (event.keyCode==13)  //回车键的键值为13
            document.getElementById("subBtn").click(); //调用登录按钮的登录事件
    }


</script>
</body>
</html>
